package com.chenkun.controller;

import com.chenkun.common.define.CommRes;
import com.chenkun.pojo.JobInfo;
import com.chenkun.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chenkun on 2017/5/14.
 */
@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
    private JobService jobService;

    @RequestMapping("/list")
    public @ResponseBody CommRes getAllJobs(){
        return this.jobService.getAllJobs();
    }

    @RequestMapping("/add")
    public @ResponseBody CommRes addJob(@RequestBody JobInfo jobInfo){
        if (jobInfo == null || jobInfo.getCode()==0){
            return CommRes.error("-2","参数错误");
        }
        return this.jobService.addJob(jobInfo);
    }

    @RequestMapping("/delete/{code}")
    public @ResponseBody CommRes deleteJob(@PathVariable int code){
        if (code == 0){
            return CommRes.error("-2","参数错误");
        }
        return this.jobService.deleteJob(code);
    }

    @RequestMapping("/get/{id}")
    public @ResponseBody CommRes getByCode(@PathVariable int id){
        if (id == 0){
            return CommRes.error("-2","参数错误");
        }
        return this.jobService.getById(id);
    }

    @RequestMapping("/update")
    public @ResponseBody CommRes updateJob(@RequestBody JobInfo jobInfo){
        if (jobInfo == null || jobInfo.getCode()==0){
            return CommRes.error("-2","参数错误");
        }
        return this.jobService.updateJob(jobInfo);
    }

}
